package nqueens.chessStuff;

public class Square {

    private int row, column; // the row and column that this square exists on
    private int attacked; // the number of queens that are 'attacking' or 'threatening' this square
    private Queen queen; // the queen placed on this square, or null if no queen

    /**
     * Constructor for a square.
     * @param row The row this square is located in.
     * @param column The column this square is located in.
     */
    public Square (int row, int column) {
        this.row = row;
        this.column = column;
        attacked = 0;
    }

    /**
     * Method that returns wether or not this square is being attacked or threatened
     * by a queen.
     * @return Boolean representing whether or not this square is being threatened.
     */
    public boolean isAttacked() {
        return attacked > 0;
    }

    /**
     * Increment the 'attacked' counter implying another queen is now threatening this square.
     */
    public void incrementAttacked() {
        this.attacked++;
    }

    /**
     * Decrement the 'attacked' counter implying a queen is no longer threatening this square.
     */
    public void decrementAttacked() {
        this.attacked--;
    }

    /**
     * Determine whether this square already has a queen or not
     * @return Boolean representing whether or not this square is being threatened.
     */
    public boolean isOccupied () {
        return queen != null;
    }

    /**
     * Used to place a queen at this square
     * @param queen the queen placed on this square
     */
    public void placeQueen ( Queen queen ) {
        this.queen = queen;
    }

    /**
     * Remove the queen from this squaree
     */
    public void removeQueen () {
        queen = null;
    }

    /**
     * Get the row this square occupies
     * @return the row this square occupies
     */
    public int getRow() {
        return row;
    }

    /**
      * Get the column this square occupies
     * @return the column this square occupies
     */
    public int getColumn() {
        return column;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Square other = (Square) obj;
        if (this.row != other.row) {
            return false;
        }
        if (this.column != other.column) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 53 * hash + this.row;
        hash = 53 * hash + this.column;
        return hash;
    }


}
